package gui.manage;

import gui.alert;
import pojo.User;
import service.UserService;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class add_manage {
    private JTextField passwd;
    private JTextField level;
    private JButton 确认添加Button;
    private JPanel sadas;

    public add_manage() {
        确认添加Button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                User u = new User();
                u.setMpassword(passwd.getText());
                u.setMlimits(level.getText());
                if (UserService.insert(u)==1){
                    alert.show("添加成功");
                }else {
                    alert.show("添加失败");
                }
            }
        });
    }

    public static void show() {
        JFrame frame = new JFrame("添加员工");
        frame.setContentPane(new add_manage().sadas);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
